<template>
  <basic-container>
    <el-tabs type="border-card" class="informationLabel" style="margin-bottom: 20px">
      <el-tab-pane label="标签生成">
        <el-row>
          <el-col :span="12">
            <avue-form class="newFormStyle" ref="otherLabelCreateForm" v-model="otherLabelCreateForm" :option="otherLabelCreateOption"></avue-form>
          </el-col>
          <el-col :span="12">
            <print-template :url="url" ref="printInfo" templateType="MATERIAL" @getPrintInfo="getPrintInfo"></print-template>
            <div style="display: flex; justify-content: flex-end">
              <el-button type="primary" size="small" icon="el-icon-printer" @click="printTest">打印测试</el-button>
              <el-button type="primary" size="small" icon="el-icon-printer" @click="batchPrinting">打印标签</el-button>
            </div>
          </el-col>
        </el-row>
      </el-tab-pane>
    </el-tabs>
    <!-- 操作日志 -->
    <operation-log ref="operationLog"></operation-log>
    <!-- 选择收料记录组件 -->
    <common-modal-template ref="commonModalTemplate" :option="tableOption" @getSelectedRows="getSelectedRows" :key="timer" @newKey="newKey"></common-modal-template>
    <!-- <select-productpackingconfig-modal
      ref="selectProductpackingconfigModal"
      :option="tableOption"
      @getSelectedRows="getSelectedRows"
      :key="timer"
      @newKey="newKey"
    ></select-productpackingconfig-modal> -->
  </basic-container>
</template>
<script>
import CommonModalTemplate from '@/components/common-modal-template/common-modal-template.vue';
import printTemplate from '@/views/product/components/printTemplate';
import { getSeqNoRules } from '@/util/global';
import { getYearWeek, showSuccessLog, showFailLog } from '@/util/helpers';
import { printTest, printlabelSequence } from '@/api/labelManagement/otherLabelPrint.js';
import OperationLog from '@/components/operation-log/operation-log.vue';
import selectProductpackingconfigModal from '@/components/selectProductpackingconfigModal.vue';
import request from '@/router/axios';
import { getCategory } from '@/api/warehouse/materialRules';
export default {
  components: {
    CommonModalTemplate,
    printTemplate,
    OperationLog,
    selectProductpackingconfigModal
  },
  data() {
    return {
      url: '/api/mes-admin/labeltemplate/page?typeList=device,manufacturing_process,quality,region2&status=1',
      otherLabelCreateForm: {}, //其他标签生成表单
      otherLabelCreateOption: {
        //其他标签生成表单配置
        labelPosition: 'right',
        labelWidth: 150,
        // menuBtn: true,
        submitBtn: false,
        submitText: '生成标签',
        emptyBtn: false,
        menuPosition: 'right',
        column: [
          {
            label: '大类',
            prop: 'mainCode',
            type: 'select',
            span: 24,
            clearable: false,
            rules: [
              {
                required: true,
                trigger: 'submit',
                validator: (rule, value, callback) => {
                  callback();
                }
              }
            ],
            dicUrl: '/api/blade-system/dict/dictionary?code=sysSerial',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            },
            change: ({ column, value }) => {
              this.otherLabelCreateForm.subCode = '';
              this.getSubTypeData(value);
            }
            // change: (val) => {
            //   this.getsubCodeList(val.value);
            // }
          },
          {
            label: '小类',
            prop: 'subCode',
            type: 'select',
            dicData: [],
            span: 24,
            clearable: false,
            rules: [
              {
                required: true,
                trigger: 'submit',
                validator: (rule, value, callback) => {
                  callback();
                }
              }
            ],
            change: (val) => {
              this.subCodeChange(val.value);
            }
          },
          {
            label: '工单号',
            prop: 'sourceName',
            span: 24,
            type: 'search',
            placeholder: '请选择 工单号',
            disabled: true,
            rules: [
              {
                required: true,
                trigger: 'submit',
                validator: (rule, value, callback) => {
                  callback();
                }
              }
            ],
            appendClick: () => {
              this.openCommonModal();
            }
          }
        ]
      },
      timer: new Date().getTime(),
      modalName: '', //打开公用模态框名称
      tableOption: {}, //公用模态框配置信息
      sequenceRuleInfo: {}, //产品序列号规则信息

      timeConfigModel: false, //序列号规则时间修改模态框是否显示
      timeConfig: {}, //序列号规则时间配置

      printInfo: {}, //打印机打印模版信息

      selectionList: [],
      extFields: ''
    };
  },
  mounted() {
    this.timeConfig.year = this.timeConfig.year ? this.timeConfig.year : this.$moment().format('YYYY');
    this.timeConfig.month = this.timeConfig.month ? this.timeConfig.month : this.$moment().format('MM');
    this.timeConfig.week = this.timeConfig.week ? this.timeConfig.week : getYearWeek();
    this.timeConfig.day = this.timeConfig.day ? this.timeConfig.day : this.$moment().format('DD');
  },
  methods: {
    async getSubTypeData(val) {
      try {
        let subCode = this.findObject(this.otherLabelCreateOption.column, 'subCode');
        const res = await getCategory({ code: val });
        const data = (res.data.data || []).map((item) => ({
          label: item.dictValue,
          value: item.dictKey
        }));
        subCode.dicData = data;
      } catch (e) {
        subCode.dicData = [];
        console.warn(e);
      }
    },
    subCodeChange(subCode) {
      let sourceName = this.findObject(this.otherLabelCreateOption.column, 'sourceName');
      // let dictKey = subCode ? JSON.parse(subCode).dictKey : '';
      switch (subCode) {
        case 'workorder':
          sourceName.label = '工单号';
          sourceName.placeholder = '请选择 工单号';

          break;
        case 'flow_card':
          sourceName.label = '流程卡';
          sourceName.placeholder = '请选择 流程卡';

          break;
        case 'warehouse':
          sourceName.label = '仓库';
          sourceName.placeholder = '请选择 仓库';

          break;
        case 'workstation':
          sourceName.label = '产线';
          sourceName.placeholder = '请选择 产线';

          break;
        case 'storage_area':
          sourceName.label = '存储区域';
          sourceName.placeholder = '请选择 存储区域';

          break;
        case 'equipement':
          sourceName.label = '设备及其属性';
          sourceName.placeholder = '请选择 设备及其属性';

          break;
        case 'tool':
          sourceName.label = '工装/夹具';
          sourceName.placeholder = '请选择 工装/夹具';

          break;
        case 'vehicle':
          sourceName.label = '载具';
          sourceName.placeholder = '请选择 载具';

          break;
        case 'inspection_results':
          sourceName.label = '检验结果';
          sourceName.placeholder = '请选择 检验结果';

          break;
        case 'fault_phenomenon':
          sourceName.label = '故障现象/故障类别';
          sourceName.placeholder = '请选择 故障现象/故障类别';
          break;
        case 'pallet':
          sourceName.label = '栈板';
          sourceName.placeholder = '请选择 栈板';

          break;
        default:
          break;
      }
      this.otherLabelCreateForm.sourceName = '';
      this.otherLabelCreateForm.sourceIds = '';
    },
    /**
     * 重新加载公用表格弹窗组件
     */
    newKey() {
      this.timer = new Date().getTime();
    },
    /**
     * 打开选择物料模态框
     */
    openPartCommonModal() {
      this.modalName = 'partModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择物料（双击进行选择）',
        url: '/api/mes-admin/part-master/page?semifinished=false',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '类型',
            prop: 'categoryId',
            search: true,
            type: 'tree',
            dicUrl: '/api/mes-admin/part-category/tree',
            props: {
              label: 'title',
              value: 'id'
            }
          },
          {
            label: '编码',
            prop: 'partNo',
            search: true
          },
          {
            label: '名称',
            prop: 'name',
            search: true
          },
          {
            label: '型号',
            prop: 'partModel'
          },
          {
            label: '描述',
            prop: 'description'
          },
          {
            label: '版本',
            prop: 'revision'
          }
        ]
      };
    },

    /**
     * 打开序列号规则选择模态框
     */
    openSerialnoCommonModal() {
      this.modalName = 'serialnoModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择序列号规则（双击进行选择）',
        url: '/api/mes-admin/sequencedefinition/page',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '序列号规则名称',
            prop: 'name',
            search: true,
            searchLabelWidth: 150,
            searchSpan: 8
          },
          {
            label: '序列号规则编码',
            prop: 'code',
            search: true,
            searchLabelWidth: 150,
            searchSpan: 8
          },
          {
            label: '进制符',
            prop: 'hexString'
          },
          {
            label: '起始流水号',
            prop: 'startSequenceNo'
          },
          {
            label: '序列号规则',
            prop: 'sequenceNoFormat'
          }
        ]
      };
    },

    /**
     * 获取打印机和打印模版信息
     */
    getPrintInfo(printInfo) {
      if (printInfo.printersId) {
        this.printInfo.printersId = printInfo.printersId;
      }
      if (printInfo.labelTemplateId) {
        this.printInfo.labelTemplateId = printInfo.labelTemplateId;
      }
    },
    //解析
    handleAnalysis() {
      const regex = /\[(.*?)\]/g;
      const tempSequenceNoFormat = this.sequenceRuleInfo.sequenceNoFormat.toLowerCase().match(regex);
      const sequenceNoFormat = tempSequenceNoFormat.map((match) => match.slice(1, -1));
      const sequenceNoFormatZh = this.sequenceRuleInfo.sequenceNoFormatZh.split('+');
      const length = this.saleReturnKey.length;
      const column = [];
      const key = []; //存储分析出来的label的key
      sequenceNoFormat.forEach((item, index) => {
        if (item !== 's') {
          key.push(item);
          column.push({
            label: sequenceNoFormatZh[index],
            prop: item,
            span: 12,
            tip: sequenceNoFormatZh[index],
            tipPlacement: 'top'
          });
        }
      });
      this.saleReturnKey = key;
      // 防止单个条码一直解析
      if (this.saleOrderReturnOption.column.length < this.saleReturnKey.length + 8) {
        this.saleOrderReturnOption.column.splice(7, 0, ...column);
      }
    },
    handleSelect(val) {
      this.saleOrderReturnForm.quantity = this.saleReturnList.find((item) => item.partMasterId === val).quantity || 0;
    },
    async getSaleReturnList(params) {
      try {
        this.saleReturnLoading = true;
        const res = await getSalesReturnList(params);
        this.saleReturnList = res.data.data.records;
      } catch (e) {
        console.warn(e);
      } finally {
        this.saleReturnLoading = false;
      }
    },
    /**
     * 标签打印
     */
    async batchPrinting() {
      if (!this.printInfo.printersId) {
        this.$message({
          type: 'warning',
          message: '请选择打印机！'
        });
        return;
      }
      if (!this.printInfo.labelTemplateId) {
        this.$message({
          type: 'warning',
          message: '请选择标签模版！'
        });
        return;
      }
      if (!this.extFields) {
        this.$message.warning('请选择打印内容！');
        return;
      }
      let params = {
        extFields: this.extFields,
        printId: this.printInfo.printersId,
        labelTemplateId: this.printInfo.labelTemplateId,
        isPrintRecord: false
      };
      printlabelSequence(params).then(
        (res) => {
          this.extFields = '';
          this.otherLabelCreateForm.sourceName = '';
          this.otherLabelCreateForm.sourceIds = '';
          this.$message({
            type: 'success',
            message: res.data.msg
          });
          showSuccessLog(res.data.msg);
        },
        (error) => {
          showFailLog(error.data.msg);
        }
      );
    },
    /**
     * 获取打印机
     */
    openPrintersModal() {
      this.modalName = 'printersModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择打印机（双击进行选择）',
        url: '/api/mes-product/ems-equipment/page?type=PRINTER',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '打印机编码',
            prop: 'code',
            search: true,
            searchLabelWidth: 110
          },
          {
            label: '打印机名称',
            prop: 'name',
            search: true,
            searchLabelWidth: 110
          }
        ]
      };
    },
    /**
     * 打开标签模板模态框
     */
    openLabelTemplateModal() {
      this.modalName = 'labelTemplateModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择标签模版（双击进行选择）',
        url: '/api/mes-admin/labeltemplate/page?status=1',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '标签名称',
            prop: 'fileName',
            search: true
          },
          {
            label: '标签代码',
            prop: 'code',
            search: true
          },
          {
            label: '版本名称',
            prop: 'revision'
          },
          {
            label: '缩略图',
            prop: 'thumbnailUrl'
          },
          {
            label: '打印标签',
            prop: 'fileUrl'
          }
        ]
      };
    },
    openCommonModal() {
      console.log(111);
      let subCode = this.otherLabelCreateForm.subCode;
      if (!subCode) {
        this.$message.warning('请选择大小类！');
        return;
      }
      switch (subCode) {
        case 'workorder':
          this.modalName = 'workorderModal';
          this.$refs.commonModalTemplate.showModal();
          this.tableOption = {
            modalTitle: '选择制程-工单号',
            url: '/api/mes-product/work-order/page',
            isPage: true,
            rowSelectionType: 'multiple',
            columnDefs: [
              {
                label: '工单类型',
                prop: 'orderType',
                type: 'select',
                dicUrl: '/api/blade-system/dict/dictionary?code=order_type',
                props: {
                  label: 'dictValue',
                  value: 'dictKey'
                },
                search: true
              },
              {
                label: '工单号',
                prop: 'orderNo',
                search: true
              },
              {
                label: '派工产线',
                prop: 'productionLineNames',
                search: true,
                searchType: 'input',
                type: 'search'
              }
            ]
          };
          break;
        case 'flow_card':
          this.modalName = 'stationModal';
          this.$refs.commonModalTemplate.showModal();
          this.tableOption = {
            modalTitle: '选择制程-流程卡',
            url: '/api/mes-product/workorder-station/work-order-station-line-info',
            isPage: true,
            rowSelectionType: 'multiple',
            columnDefs: [
              {
                label: '工单类型',
                prop: 'orderType',
                type: 'select',
                dicUrl: '/api/blade-system/dict/dictionary?code=order_type',
                props: {
                  label: 'dictValue',
                  value: 'dictKey'
                },
                search: true
              },
              {
                label: '工单号',
                prop: 'workOrderNo',
                search: true
              },
              {
                label: '派工产线',
                prop: 'lineName',
                search: true,
                searchType: 'input',
                type: 'search'
              },
              {
                label: '工序',
                prop: 'stationRouteName',
                search: true
              }
            ]
          };
          break;
        case 'warehouse':
          this.modalName = 'warehouseModal';
          this.$refs.commonModalTemplate.showModal();
          this.tableOption = {
            modalTitle: '选择区域-仓库',
            url: '/api/mes-admin/area/page/storage/management?areaType=WAREHOUSE',
            isPage: true,
            rowSelectionType: 'multiple',
            searchLabelWidth: 100,
            columnDefs: [
              {
                label: '仓库编码',
                prop: 'code',
                search: true
              },
              {
                label: '仓库名称',
                prop: 'name',
                search: true
              },
              {
                label: '仓库类型',
                prop: 'inventoryType',
                search: true,
                type: 'select',
                props: {
                  label: 'dictValue',
                  value: 'dictKey'
                },
                dicUrl: '/api/blade-system/dict/dictionary?code=inventory_type'
              }
            ]
          };
          break;
        case 'workstation':
          this.modalName = 'lineModal';
          this.$refs.commonModalTemplate.showModal();
          this.tableOption = {
            modalTitle: '选择区域-产线（工位）',
            url: '/api/mes-product/productionline/page',
            isPage: true,
            rowSelectionType: 'multiple',
            columnDefs: [
              {
                label: '产线编码',
                prop: 'code',
                search: true
              },
              {
                label: '产线名称',
                prop: 'name',
                search: true
              },
              {
                label: '所属车间',
                prop: 'workshopId',
                type: 'select',
                search: true,
                props: {
                  label: 'workshopName',
                  value: 'workshopId'
                },
                dicUrl: '/api/mes-admin/workshop/key-value'
              }
            ]
          };
          break;
        case 'storage_area':
          this.modalName = 'storageModal';
          this.$refs.selectProductpackingconfigModal.showModal();
          this.tableOption = {
            modalTitle: '选择区域-存储区域',
            url: '/api/mes-admin/area/page/storage/management?areaType=STORAGE',
            isPage: true,
            rowSelectionType: 'multiple',
            lazy: true,
            lazyUrl: '/api/mes-admin/area/select/storage/management',
            searchLabelWidth: 100,
            columnDefs: [
              {
                label: '存储区域编码',
                prop: 'code',
                search: true
              },
              {
                label: '存储区域名称',
                prop: 'name',
                search: true
              },
              {
                label: '存储区域类型',
                prop: 'areaTypeName',
                search: true,
                type: 'select',
                dicData: [
                  { label: '储位区', value: 'STORAGE_AREA' },
                  { label: '储位', value: 'STORAGE' }
                ]
              }
            ]
          };
          break;
        case 'equipement':
          this.modalName = 'equipmentModal';
          this.$refs.commonModalTemplate.showModal();
          this.tableOption = {
            modalTitle: '选择设备-设备及其属性',
            url: '/api/mes-product/ems-equipment/page?type=PRINTER',
            isPage: true,
            rowSelectionType: 'multiple',
            columnDefs: [
              {
                label: '设备编码',
                prop: 'code',
                search: true
              },
              {
                label: '设备名称',
                prop: 'name',
                search: true
              },
              {
                label: '设备类型',
                prop: 'categoryId',
                search: true,
                type: 'select',
                dicUrl: '/api/mes-product/ems-equipment-category/page?current=1&size=100',
                props: {
                  label: 'name',
                  value: 'id'
                },
                dicFormatter: (data) => {
                  return data.data.records;
                }
              }
            ]
          };
          break;
        case 'tool':
          this.modalName = 'tool';
          this.$refs.commonModalTemplate.showModal();
          this.tableOption = {
            modalTitle: '选择设备-工装/夹具',
            url: '/api/mes-product/ems-equipment/page?type=PRINTER',
            method: 'get',
            isPage: true,
            rowSelectionType: 'multiple',
            searchLabelWidth: 150,
            columnDefs: [
              {
                label: '工装/夹具编码',
                prop: 'code',
                search: true
              },
              {
                label: '工装/夹具名称',
                prop: 'name',
                search: true
              },
              {
                label: '工装/夹具类型',
                prop: 'subType',
                type: 'select',
                search: true,
                dicUrl: '/api/blade-system/dict/dictionary?code=mes_equipment_tool_type',
                props: {
                  label: 'dictValue',
                  value: 'dictKey'
                },
                rules: [
                  {
                    required: true,
                    message: '请选择栈板类型',
                    trigger: 'blur'
                  }
                ]
              }
            ]
          };
          break;
        case 'vehicle':
          this.modalName = 'vehicleModal';
          this.$refs.commonModalTemplate.showModal();
          this.tableOption = {
            modalTitle: '选择设备-载具',
            url: '/api/mes-product/carrier/listCarrier',
            method: 'post',
            isRequestor: true,
            isPage: true,
            rowSelectionType: 'multiple',
            columnDefs: [
              {
                label: '编码',
                prop: 'sequenceNumber',
                search: true
              },
              {
                label: '名称',
                prop: 'name',
                search: true
              },
              {
                label: '类型',
                prop: 'carrierType',
                type: 'select',
                search: true,
                dicUrl: '/api/blade-system/dict/dictionary?code=carrier_type',
                props: {
                  label: 'dictValue',
                  value: 'dictKey'
                }
              }
            ]
          };
          break;
        case 'inspection_results':
          this.modalName = 'resultModal';
          this.$refs.commonModalTemplate.showModal();
          this.tableOption = {
            modalTitle: '选择品质-检验结果',
            url: '/api/mes-product/inspection-document/page?descs=send_examine_date&statusStr=2,3',
            method: 'get',
            isPage: true,
            rowSelectionType: 'multiple',
            columnDefs: [
              {
                label: '检验类型',
                prop: 'documentType',
                search: true,
                type: 'select',
                dicData: [
                  { label: 'IQC', value: 'IQC' },
                  { label: 'FQC', value: 'FQC' },
                  { label: 'OQC', value: 'OQC' },
                  { label: 'IPQC', value: 'IPQC' }
                ]
              },
              {
                label: '检验单号',
                prop: 'documentNo',
                search: true
              },
              {
                label: '检验结果',
                prop: 'examineResult',
                type: 'select',
                search: true,
                dicData: [
                  { label: '合格', value: 'OK' },
                  { label: '不合格', value: 'NG' }
                ]
              }
            ]
          };
          break;
        case 'fault_phenomenon':
          this.modalName = 'phenomenonModal';
          this.$refs.commonModalTemplate.showModal();
          this.tableOption = {
            modalTitle: '选择品质-故障现象',
            url: '/api/mes-product/mro-dict/page?dictType=FAILURE',
            method: 'get',
            isPage: true,
            rowSelectionType: 'multiple',
            columnDefs: [
              {
                label: '故障编码',
                prop: 'code',
                search: true
              },
              {
                label: '故障名称',
                prop: 'name',
                search: true
              }
            ]
          };
          break;
        case 'pallet':
          this.modalName = 'pallet';
          this.$refs.commonModalTemplate.showModal();
          this.tableOption = {
            modalTitle: '选择设备-栈板',
            url: '/api/mes-warehouse/pallet/page',
            method: 'get',
            isPage: true,
            rowSelectionType: 'multiple',
            columnDefs: [
              {
                label: '栈板名称',
                prop: 'name',
                search: true
              },
              {
                label: '栈板编码',
                prop: 'sequenceNumber',
                search: true
              },
              {
                label: '栈板类型',
                prop: 'typeCode',
                type: 'select',
                search: true,
                dicUrl: '/api/blade-system/dict/dictionary?code=pallet_type',
                props: {
                  label: 'dictValue',
                  value: 'dictKey'
                },
                rules: [
                  {
                    required: true,
                    message: '请选择栈板类型',
                    trigger: 'blur'
                  }
                ]
              }
            ]
          };
          break;
        default:
          break;
      }
    },
    /**
     * 获取选择的模态框行数据
     */
    getSelectedRows(rowData) {
      this.otherLabelCreateForm.sourceName = '';
      this.otherLabelCreateForm.sourceIds = '';
      if (rowData.length > 1) {
        this.$message.warning('请选择一条数据打印！');
        return;
      }
      let sourceName = [];
      let sourceIds = [];
      switch (this.modalName) {
        case 'workorderModal':
          this._forEach(rowData, (item) => {
            sourceName.push(item.orderNo);
            sourceIds.push(item.id);
          });
          this.otherLabelCreateForm.sourceName = sourceName;
          this.otherLabelCreateForm.sourceIds = sourceIds;
          this.extFields = JSON.stringify(rowData[0]);
          break;
        case 'stationModal':
          this._forEach(rowData, (item) => {
            sourceName.push(item.stationRouteName);
            sourceIds.push(item.id);
          });
          this.otherLabelCreateForm.sourceName = sourceName;
          this.otherLabelCreateForm.sourceIds = sourceIds;
          this.extFields = JSON.stringify(rowData[0]);
          break;
        case 'warehouseModal':
          this._forEach(rowData, (item) => {
            sourceName.push(item.name);
            sourceIds.push(item.id);
          });
          this.otherLabelCreateForm.sourceName = sourceName;
          this.otherLabelCreateForm.sourceIds = sourceIds;
          this.extFields = JSON.stringify(rowData[0]);
          break;
        case 'lineModal':
          this._forEach(rowData, (item) => {
            sourceName.push(item.name);
            sourceIds.push(item.id);
          });
          this.otherLabelCreateForm.sourceName = sourceName;
          this.otherLabelCreateForm.sourceIds = sourceIds;
          this.extFields = JSON.stringify(rowData[0]);
          break;
        case 'storageModal':
          this._forEach(rowData, (item) => {
            sourceName.push(item.name);
            sourceIds.push(item.id);
          });
          this.otherLabelCreateForm.sourceName = sourceName;
          this.otherLabelCreateForm.sourceIds = sourceIds;
          this.extFields = JSON.stringify(rowData[0]);
          break;
        case 'equipmentModal':
          this._forEach(rowData, (item) => {
            sourceName.push(item.name);
            sourceIds.push(item.id);
          });
          this.otherLabelCreateForm.sourceName = sourceName;
          this.otherLabelCreateForm.sourceIds = sourceIds;
          this.extFields = JSON.stringify(rowData[0]);
          break;
        case 'vehicleModal':
          this._forEach(rowData, (item) => {
            sourceName.push(item.name);
            sourceIds.push(item.id);
          });
          this.otherLabelCreateForm.sourceName = sourceName;
          this.otherLabelCreateForm.sourceIds = sourceIds;
          this.extFields = JSON.stringify(rowData[0]);
          break;
        case 'resultModal':
          this._forEach(rowData, (item) => {
            sourceName.push(item.documentNo);
            sourceIds.push(item.id);
          });
          this.otherLabelCreateForm.sourceName = sourceName;
          this.otherLabelCreateForm.sourceIds = sourceIds;
          this.extFields = JSON.stringify(rowData[0]);
          break;
        case 'phenomenonModal':
          this._forEach(rowData, (item) => {
            sourceName.push(item.name);
            sourceIds.push(item.id);
          });
          console.log(sourceName);
          this.otherLabelCreateForm.sourceName = sourceName;
          this.otherLabelCreateForm.sourceIds = sourceIds;
          this.extFields = JSON.stringify(rowData[0]);
          break;
        case 'tool':
          this._forEach(rowData, (item) => {
            sourceName.push(item.name);
            sourceIds.push(item.id);
          });
          this.otherLabelCreateForm.sourceName = sourceName;
          this.otherLabelCreateForm.sourceIds = sourceIds;
          this.extFields = JSON.stringify(rowData[0]);
          break;
        case 'pallet':
          this._forEach(rowData, (item) => {
            sourceName.push(item.name);
            sourceIds.push(item.id);
          });
          this.otherLabelCreateForm.sourceName = sourceName;
          this.otherLabelCreateForm.sourceIds = sourceIds;
          this.extFields = JSON.stringify(rowData[0]);
          break;
        case 'printersModal':
          this.printInfo.printersId = this._get(rowData, 'id', '');
          this.printInfo.equipmentName = this._get(rowData, 'name', '');
          this.extFields = JSON.stringify(rowData[0]);
          break;
        case 'labelTemplateModal':
          this.printInfo.labelTemplateId = this._get(rowData, 'id', '');
          this.printInfo.labelTemplateName = this._get(rowData, 'fileName', '');
          this.extFields = JSON.stringify(rowData[0]);
          break;

        default:
          break;
      }
    },

    /**
     * 打印测试
     */
    async printTest() {
      if (!this.printInfo.printersId) {
        this.$message({
          type: 'warning',
          message: '请选择打印机！'
        });
        return;
      }
      if (!this.printInfo.labelTemplateId) {
        this.$message({
          type: 'warning',
          message: '请选择标签模版！'
        });
        return;
      }
      let params = {
        printId: this.printInfo.printersId,
        labelTemplateId: this.printInfo.labelTemplateId
      };
      printTest(params).then((res) => {
        this.$message({
          type: 'success',
          message: res.data.msg
        });
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.sequenceInfo {
  table {
    width: 100%;
    height: auto;
    margin-bottom: 10px;
    font-size: 14px;
    th {
      border: 1px solid #ebeef5;
      background: #fafafa;
      height: 30px;
    }
    tr {
      border: 1px solid #ebeef5;
    }
    td {
      border: 1px solid #ebeef5;
      height: auto;
      text-align: center;
    }
    p {
      margin-left: 30px;
    }
  }
}
.newFormStyle {
  ::v-deep .el-form-item--small.el-form-item {
    margin-bottom: 5px;
  }
  ::v-deep .el-input--small input {
    height: 30px;
    line-height: 30px;
  }
}
.generateSerialNoInfo {
  div {
    margin: 5px 10px;
  }
}
.printButton {
  text-align: right;
}
::v-deep .el-button--primary {
  background-color: #5badc4;
  color: #ffffff;
}
.sale_order_return {
  ::v-deep .el-form-item__label {
    white-space: nowrap; /* 禁止换行 */
    overflow: hidden;
    text-overflow: ellipsis; /* 超出部分显示省略号 */
  }
}
.informationLabel {
  ::v-deep .avue-crud__menu {
    display: none;
  }
}
</style>
